package org.cnc.gui;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class SettingsPanel extends JPanel implements ChangeListener {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ChangeListener changeListener;
	
	private final JSpinner xMax = new JSpinner();
	private final JSpinner yMax = new JSpinner();
	private final JSpinner zMax = new JSpinner();
	private final JSpinner tZad = new JSpinner();
	
	@Override
	public void stateChanged(ChangeEvent e)
	{
		changeListener.stateChanged(new ChangeEvent(this));
	}
	
	public void addChangeListener( ChangeListener listener )
	{
		changeListener = listener;
	}
	
	public int getXMax() { return (Integer) xMax.getValue(); }
	public int getYMax() { return (Integer) yMax.getValue(); }
	public int getZMax() { return (Integer) zMax.getValue(); }
	public int getTZad() { return (Integer) tZad.getValue(); }
	
	public SettingsPanel( )
	{
		setPreferredSize(new Dimension(240, 263));
		InitGui();
	}
	
	public void InitGui() {
		
		JLabel lblXmax = new JLabel("Xmax");
		lblXmax.setForeground(Color.LIGHT_GRAY);
		
		xMax.setModel(new SpinnerNumberModel(1, 1, 20, 1));
		xMax.addChangeListener(this);
		
		JLabel lblZmax = new JLabel("Ymax");
		lblZmax.setForeground(Color.LIGHT_GRAY);
		
		yMax.setToolTipText("Zmax");
		yMax.setModel(new SpinnerNumberModel(1, 1, 4, 1));
		
		yMax.addChangeListener(this);
		
		JLabel lblYmax = new JLabel("Zmax");
		lblYmax.setForeground(Color.LIGHT_GRAY);
		
		zMax.setModel(new SpinnerNumberModel(1, 1, 10, 1));
		
		zMax.addChangeListener(this);
		
		JLabel lblTzad = new JLabel("Tzad");
		lblTzad.setForeground(Color.LIGHT_GRAY);
		
		tZad.setModel(new SpinnerNumberModel(500, 1, 30000, 100));
		
		tZad.addChangeListener(this);
		
		JLabel label = new JLabel("\u041D\u0430\u0441\u0442\u0440\u043E\u0439\u043A\u0438 \u0432\u044B\u0440\u0435\u0437\u0430:");
		label.setForeground(Color.LIGHT_GRAY);
		
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(25)
							.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblXmax)
									.addGap(18)
									.addComponent(xMax, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblZmax)
									.addGap(18)
									.addComponent(yMax, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblYmax)
									.addGap(18)
									.addComponent(zMax, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE))
								.addGroup(groupLayout.createSequentialGroup()
									.addComponent(lblTzad)
									.addGap(22)
									.addComponent(tZad, GroupLayout.PREFERRED_SIZE, 106, GroupLayout.PREFERRED_SIZE))))
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(55)
							.addComponent(label)))
					.addContainerGap(62, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(23)
					.addComponent(label)
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(1)
							.addComponent(lblXmax))
						.addComponent(xMax, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(1)
							.addComponent(lblZmax))
						.addComponent(yMax, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(13)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(1)
							.addComponent(lblYmax))
						.addComponent(zMax, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(13)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
						.addGroup(groupLayout.createSequentialGroup()
							.addGap(1)
							.addComponent(lblTzad))
						.addComponent(tZad, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addContainerGap(58, Short.MAX_VALUE))
		);
		groupLayout.setAutoCreateGaps(true);
		groupLayout.setAutoCreateContainerGaps(true);
		
		setLayout(groupLayout);
	}
}
